<template>
	<div>

		<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch"
			v-if="currentType!='user'">
			<a-row :gutter="24">

				<a-col :span="8">
					<a-form-item label="年审名称">
						<a-input autocomplete="off" class="field-right" placeholder="请输入年审名称搜索" v-decorator="[`key`]" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="组织名称">
						<a-input autocomplete="off" class="field-right" placeholder="请输入组织名称搜索" v-decorator="[`clubName`]" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="组织类型">
						<a-select :allowClear="true" v-decorator="['clubTypeID']" placeholder="全部" optionFilterProp="children" showSearch>
							<a-select-option v-for="(item, index) in TypeIDList" :key="index" :value="item.ID">{{ item.Name }}</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="8" v-if="currentState==1">
					<a-form-item label="是否通过">
						<a-select :allowClear="true" v-decorator="['isAdopt']" placeholder="全部"
							optionFilterProp="children" showSearch>
							<a-select-option v-for="(item, index) in isAdoptList" :key="item.Key" :value="item.Key">
								{{ item.Value }}
							</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
			
                <ClubSearch :span="8" label="申报人" name="applyUserNo" ref="applyUserNo" @tap="searchValueFun">	</ClubSearch>
				<!-- <ClubSearch :span="8" label="审批人" name="examUserNo" ref="examUserNo" @tap="searchValueFun">
				</ClubSearch> -->
				<a-col :span="8" style="margin-top: 4px;">
					<a-button-group class="btngroupoption" >
						<a-button type="primary" @click="handleSearch">搜索</a-button>
						<a-button @click="handleReset">重置</a-button>
						<!-- <a-button type="primary" class="btn" @click="allApplyHander" v-if="currentState==0&&currentType!='manager'">批量审核</a-button> -->
					</a-button-group>
				</a-col>
			</a-row>
		</a-form>

		<div class="table">

			<el-table :data="data" v-loading="loading" :border="$route.path.includes('Home')" highlight-current-row
				style="width: 100%;" @selection-change="handleSelectionChange">
				<!-- <el-table-column type="selection" width="55" fixed="left" v-if="currentState==0"></el-table-column> -->
				<el-table-column type="index" label="序号" width="60" align="center"></el-table-column>
				<el-table-column prop="ClubAnnualAuditName" label="组织年审" min-width="140"></el-table-column>
				<el-table-column prop="ClubName" label="组织名称" min-width="140" v-if="currentType!='manager'"
					align="center"></el-table-column>
				<el-table-column prop="AddTime" label="申报时间" min-width="140" align="center"></el-table-column>
				<el-table-column prop="Title" label="申报人" min-width="260" align="center">
					<template slot-scope="scope">{{ scope.row.AddUserName }} / {{ scope.row.AddUserNo }} 
						</template>
				</el-table-column>
				<el-table-column prop="IsEnable" label="审核状态" min-width="130" align="center"
					v-if="currentType=='manager'">
					<template slot-scope="scope">
						<a-tag
							:color="scope.row.State==1?'red':scope.row.State==2?'#ff7f27':scope.row.State==4?'blue':scope.row.State==3?'green':'blue'">
							{{ scope.row.StateName }}
						</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="IsEnable" label="审核状态" min-width="130" align="center"
					v-if="currentState!=0&&currentType!='manager'">
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsAdopt?'green':'red'">{{ scope.row.IsAdopt?'审核通过':'审核不通过' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" min-width="140" fixed="right">
					<template slot-scope="scope">
						<div class="user-btn user-btn-auto">
							<oprateBtn title="修改"  @tap="detail(scope.row,'update')" v-if="currentState==0&&currentType=='PracticeTeamDeclareSp'&&scope.row.IsAgreeUpdate" icon="icon-editor1"
								color="#1890FF" ></oprateBtn>
							<!-- <span class="modify" @click="detail(scope.row,'update')" v-if="currentState==0&&currentType=='PracticeTeamDeclareSp'">修改</span>
							 --><!-- <span class="modify" @click="detail(scope.row,'update')" v-if="currentState==0&&currentType=='collegeFlow'&&IsAgreeUpdate">修改</span> -->
							
							<oprateBtn title="修改"  @tap="detail(scope.row,'update')" v-if="currentState==0&&currentType=='collegeFlow'&&IsAgreeUpdate" icon="icon-editor1"
								color="#1890FF" ></oprateBtn>
							<a-tooltip placement="top">
									<template slot="title">详情</template>
									<i title="详情" class="iconfont icon-xiangqing" style="color: #1890FF;"
										@click="detail(scope.row,'detail')"></i>
								</a-tooltip>
								<a-tooltip placement="top">
									<template slot="title">审批</template>
									<i title="审批" class="iconfont icon-shenpi" style="color: red;"
										@click="seeList(scope.row, 4)" v-if="currentState==0"></i>
								</a-tooltip>
							 <!-- <span class="detail" @click="detail(scope.row,'detail')">详情</span>
							<span class="examine" @click="seeList(scope.row, 4)" v-if="currentState==0">审批</span> -->
						</div>
						<!-- <div class="tableleft">
							<oprateBtn title="修改" @click="detail(scope.row,'update')" v-if="currentState==0&&currentType=='collegeFlow'&&IsAgreeUpdate"></oprateBtn>
							
						</div> -->
					
					</template>
				</el-table-column>
			</el-table>
			<pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"
				:pagination="pagination"></pagination>
		</div>
		<add :text="text" v-show="addIf" :currentType="currentType" @shenpiFun="shenpiFun" @closeFun="closeFun"></add>
		<detail :text="text" v-show="detailIf" :currentType="currentType" @shenpiFun="shenpiFun" @closeFun="closeFun">
		</detail>
	</div>
</template>

<script>
	import add from './add';
	import detail from './detail';
	import pagination from '@components/pagination/index.vue';
	import ClubSearch from '@/components/SearchForm/ClubSearch.vue'
	import moment from 'moment';
	import Cache from '@/utils/cache';
	import {
		ManagePracticeTeamDeclare,
		UserPracticeTeamDeclare,
		ManagePracticeTeamDeclareFlow,
		GetDepartList,
		CommonDoGetPracticeSessionList,
		Common,
		ManageClubAnnualAuditFlowDoGetPageList,
		UserPracticeTeamDeclareFlowDoGetPageList,
		UserClubAnnualAuditFlowDoGetPageList,
		GetClubTypeList
	} from '@/api/follow';
	import Func from '@/utils/func';
	export default {
		props: {
			currentType: String,
			currentState: Number,
			flowTypeID: String,
			IsAgreeUpdate: Boolean
		},
		components: {
			add,
			detail,
			pagination,
			ClubSearch
		},
		watch: {
			flowTypeID: function(flowTypeID) {
				console.log(this.nowflowTypeID);
				this.flowTypeID = flowTypeID;
				this.getList();
			}
		},
		data() {
			return {
				isAdoptList: this.global.isAdoptList,
				TypeIDList:[],
				detailIf: false,
				UserInfo: Cache.get('myInfo'),
				data: [{
					IsApply: true
				}],
				loading: false,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: this.global.pagination,
				addIf: false,
				text: {},
				values: {},
				multipleSelection: [],
				DepartCodeList: [],
				SessionIDList: [],
				sessionDeclareIDList: []
			};
		},
		async created() {
			this.getList();
			// this.getOtherList();
			let that = this;
			if (that.currentState == 1) {
				setTimeout(function() {
					that.getOtherList();
				}, 1000)
			} else {
				that.getOtherList();
			}
		},
		methods: {
			colorFun(type) {
				let color = 'pink';
				switch (type) {
					case 0:
						color = 'pink';
						break;
					case 1:
						color = 'red';
						break;
					case 2:
						color = 'orange';
						break;
					case 3:
						color = 'green';
						break;
					case 4:
						color = 'cyan';
						break;
				}
				return color;
			},
			moment,
			detail(text, source) {
				this.text = {
					...text,
					time: new Date(),
					btnType: source
				};
				this.detailIf = !this.detailIf;
			},
			shenpiFun(text) {
				this.addIf = !this.addIf;
				this.text = {
					...text,
					listType: 4,
					TeamID: this.$route.query.ID,
					SessionDeclareID: text.ID,
					currentType: this.currentType,
					flowID: text.flowID,
					currentState: this.currentState,
					time: new Date()
				};
				console.log(this.text)
				this.addIf = !this.addIf;
			},
			async SessionIDFun(e) {
				if (e) {
					this.form.setFieldsValue({
						sessionDeclareID: undefined
					})
					this.sessionDeclareIDList = (await Common('DoGetPracticeSessionDeclareList', {
						sessionID: e
					})).data.data
				}
			},
			searchValueFun(name, value) {
				this.values = {
					...this.values,
					[name]: value
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			allApplyHander() {
				if (this.multipleSelection.length == 0) {
					this.$message.error('请选择要处理的数据！')
					return false
				}
				this.seeList({
					ID: this.multipleSelection.map((item) => {
						return item.ID
					}).join(','),
					textArr: this.multipleSelection
				}, 4)
			},
			async getOtherList() {
				let res = await GetClubTypeList();
				this.TypeIDList = res.data.data;
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					if (values.data && values.data.length > 0) {
						values.startDate = values.data[0].format('YYYY-MM-DD HH:mm:ss')
						values.endDate = values.data[1].format('YYYY-MM-DD HH:mm:ss')
					}
					this.values = {
						...this.values,
						...values
					};
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.$refs.applyUserNo.value = undefined
				this.values = {};
				this.getList()
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				data = {
					...this.values,
					teamID: this.$route.query.ID,
					pageIndex: this.pagination.currentPage,
					pageSize: this.pagination.pageSize
				};
				let res = {};
				if (this.currentType == 'user') {
					res = await UserPracticeTeamDeclare('DoGetList', data);
				}

				if (this.currentType == 'collegeFlow') {
					data.flowTypeID = this.flowTypeID;
					if (this.currentState == 0) {
						data.isExam = false;
						res = await ManageClubAnnualAuditFlowDoGetPageList(data);
					} else {
						data.isExam = true;
						res = await ManageClubAnnualAuditFlowDoGetPageList(data);
					}

				}
				if (this.currentType == 'PracticeTeamDeclareSp') {
					if (this.currentState == 0) {
						data.isExam = false;
						res = await UserClubAnnualAuditFlowDoGetPageList(data);
					} else {
						data.isExam = true;
						res = await UserClubAnnualAuditFlowDoGetPageList(data);
					}

				}


				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo ? res.data.pageInfo.TotalItemCount : 0;
				this.pagination = pagination;
			},
			newseeList(text, listType) {
				this.text = {
					listType: listType,
					TeamID: this.$route.query.ID,
					SessionDeclareID: text.ID,
					currentType: this.currentType,
					time: new Date()
				};
				console.log(this.text)
				this.addIf = !this.addIf;
			},
			seeList(text, listType) {
				this.text = {
					...text,
					listType: listType,
					TeamID: this.$route.query.ID,
					SessionDeclareID: text.ID,
					currentType: this.currentType,
					flowID: text.ID,
					currentState: this.currentState,
					time: new Date()
				};
				console.log(this.text)
				this.addIf = !this.addIf;
			},
			setList(text, type) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: type == 1 ? `您确定删除该数据吗？` : type == 2 ? `您确定撤回该数据吗？` : '您确定给该申报补发学分吗？',
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						let res = {}
						if (that.currentType == 'manager') {
							data.id = text.ID;
							res = await ManagePracticeTeamDeclare('DoSendScore', data)
						}
						if (that.currentType == 'user') {
							data.id = text.TeamDeclareID;
							res = type == 1 ? await UserPracticeTeamDeclare('DoDelete', data) :
								await UserPracticeTeamDeclare('DoRevoke', data)
						}
						that.$message[res.data.code == 0 ? 'success' : 'error'](res.data.msg);
						if (res.data.code == 0) {
							that.getList();
						}
					}
				});
			},
			goList(item, name) {
				this.$router.push({
					name: this.currentType == 'manager' ? name : 'User' + name,
					query: {
						ID: item.ID,
					}
				});
			},
			closeFun(data) {
				this.addIf = false;
				this.detailIf = false;
				if (data == 1) {
					this.$emit('shenpiFunClose');
					this.getList();
				}
			}
		}
	};
</script>
